/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upf.grupof.projectphotos.databases;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
 *
 * @author fredi
 */
public class Handler extends org.xml.sax.helpers.DefaultHandler {
    private iPhoto photo;
    private String tempVal;
    
    private String id;
        
    public Handler(iPhoto photo){
        this.photo=photo;
    }
    
    @Override
    public void startDocument() throws SAXException {
        tempVal="";
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        tempVal = new String(ch, start, length);
    }
    
    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        tempVal="";
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        if (localName.equalsIgnoreCase("title")){
            this.photo.setTitle(tempVal);
        } else if (localName.equalsIgnoreCase("description")){
            this.photo.setDesc(tempVal);
        } else if (localName.equalsIgnoreCase("format")){
            this.photo.setFormat(tempVal);
        } else if (localName.equalsIgnoreCase("resolution")){
            this.photo.setResoultion("width","height");
        } else if (localName.equalsIgnoreCase("creation_date")){
            this.photo.setDate("dd/mm/aaaa");
        } else if (localName.equalsIgnoreCase("size")){
            this.photo.setSize(tempVal);
        } else if (localName.equalsIgnoreCase("localization")){
            this.photo.setLocation(tempVal);
        } else if (localName.equalsIgnoreCase("path")){
            this.photo.setPath(tempVal);
        } else if (localName.equalsIgnoreCase("file")){
            this.photo.setFile(tempVal);
        } else if (localName.equalsIgnoreCase("username_author")){
            this.photo.setUser(tempVal);
        }
    }
    
    @Override
    public void endDocument() throws SAXException {
    }   
}
